package coreservlets;

import java.util.*;

public class DataBase {

	private static List<User> users = new ArrayList<User>();

	public DataBase() {
		users = new ArrayList<User>();
		users.add(new User("1","123456","Chuck","Norris1","all@emails.com","Universe"));
		users.add(new User("2","123456","Chuck","Norris2","all@emails.com","Universe"));
		users.add(new User("3","123456","Chuck","Norris3","all@emails.com","Universe"));
		users.add(new User("a","123456","Chuck","Norris4","all@emails.com","Universe"));
		users.add(new User("b","123456","Chuck","Norris5","all@emails.com","Universe"));
		users.add(new User("c","123456","Chuck","Norris6","all@emails.com","Universe"));
		users.add(new User("d","123456","Chuck","Norris7","all@emails.com","Universe"));
		
	}

	public User login(User user) {		
		User u = null;
		User current = null;
		Iterator<User> userIterator = users.iterator();
		while (userIterator.hasNext()){
			current = userIterator.next();
			if (current.getId().equals(user.getId()) && current.getPassword().equals(user.getPassword())){
				u = current;
				break;
			}
		}
		return u;

	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

}
